package br.gov.cemaden.library.model.pcds;

import br.gov.cemaden.library.interfaces.UsuarioInterface;
import br.gov.cemaden.library.interfaces.pcds.RedeInterface;
import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author paulo.dias
 * 
 * @Entity
 * @Table(name = "pcds_rede", schema = "pcds")
 * @SequenceGenerator(name = "sequence", sequenceName = "pcds.pcds_rede_sequence", schema = "pcds")
 */
public abstract class BaseRede implements RedeInterface {
    
    private static final long serialVersionUID = 1L;
    
    /**
     * @Id
     * @GeneratedValue(generator = "sequence", strategy = GenerationType.AUTO)
     * @Column(name="id_rede", nullable = false, unique = true)    
     */
    protected Long id;
    
    protected String nome;
    
    protected String sigla;
    
    /**
     * @Column(name = "perc_min_functo")
     */
    protected Short percentualMinimoFuncionamento;
    
    /**
     * @Column(name = "tempo_max_sem_aquisicao")
     */
    protected Integer tempoMaximoSemAquisicao;
    
    /**
     * @ManyToMany(cascade = CascadeType.ALL)
     * @JoinTable(name = "smp_usuario_rede", schema = "smp", 
            joinColumns = {@JoinColumn(name = "id_rede")},
            inverseJoinColumns = {@JoinColumn(name = "id_usuario")})
     */
    protected Set<UsuarioInterface> usuarios = new HashSet<UsuarioInterface>();

    public BaseRede() 
    {
    }    

    public void setId(Long id) {
        this.id = id;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public void setSigla(String sigla) {
        this.sigla = sigla;
    }

    public void setPercentualMinimoFuncionamento(Short percentualMinimoFuncionamento) {
        this.percentualMinimoFuncionamento = percentualMinimoFuncionamento;
    }

    public void setTempoMaximoSemAquisicao(Integer tempoMaximoSemAquisicao) {
        this.tempoMaximoSemAquisicao = tempoMaximoSemAquisicao;
    }

    public void setUsuarios(Set<UsuarioInterface> usuarios) {
        this.usuarios = usuarios;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof BaseRede)) {
            return false;
        }
        BaseRede other = (BaseRede) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Rede{" + "idRede=" + id + ", nome=" + nome + ", sigla=" + sigla + ", percMinFuncto=" + percentualMinimoFuncionamento + ", tempoMaxSemAquisicao=" + tempoMaximoSemAquisicao + '}';
    }    
    
}
